<template>
<el-card>
  <el-card>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="患者姓名">
                <el-input v-model="formInline.patientName" placeholder="患者姓名"></el-input>
            </el-form-item>
            <el-form-item label="电话号码">
                <el-input v-model="formInline.patientPhone" placeholder="电话号码"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="ToName"  icon="el-icon-search">搜索</el-button>
            </el-form-item>
               <el-form-item>
                <el-button type="success" @click="dialogFormVisible = true" >新增就诊卡</el-button>
            </el-form-item>
        </el-form>
   </el-card> 
   <el-card>
    <el-descriptions title="患者信息" direction="vertical" :column="3"  >
    <el-descriptions-item label="姓名"  >
      <span v-text="parent.patientName"></span>
      </el-descriptions-item>
    <el-descriptions-item label="手机号" >
      <span  v-text="parent.patientPhone"></span>
    </el-descriptions-item>
    <el-descriptions-item label="身份证号"  :span="2">
      <span  v-text="parent.cardId"></span>
    </el-descriptions-item>
    <el-descriptions-item label="诊断结果">
    <el-tag size="small">  <span  v-text="parent.diagnosis"></span></el-tag>
  </el-descriptions-item>
    <el-descriptions-item label="患者年龄"> <span  v-text="parent.age"></span></el-descriptions-item>
</el-descriptions>
</el-card>
   <el-card>    
  <el-table
    :data="tableData"
    style="width: 100%">
    <el-table-column type="expand">
      <template slot-scope="props">
        <el-form label-position="left" inline class="demo-table-expand">
          <el-form-item label="患者姓名">
            <span>{{ props.row.patientName }}</span>
          </el-form-item>
          <el-form-item label="预约时间">
            <span>{{ props.row.appointment.appointmentDate }}</span>
          </el-form-item>
          <el-form-item label="费用">
            <span>{{ props.row.appointment.appointmentMoney }}</span>
          </el-form-item>
            <el-form-item label="支付状态">
            <span>{{ props.row.appointment.payWay==2?"未支付":"已支付" }}</span>
          </el-form-item>
           <el-form-item label="电话号码">
            <span>{{ props.row.patientPhone }}</span>
          </el-form-item>
        </el-form>
      </template>
    </el-table-column>
    <el-table-column
      label="患者姓名"
      prop="patientName">
    </el-table-column>
    <el-table-column
      label="预约时间"
      prop="appointment.appointmentDate">
    </el-table-column>
    <el-table-column
      label="金额"
      prop="appointment.appointmentMoney">
    </el-table-column>
  </el-table>
   </el-card>
<el-dialog title="新增就诊卡" :visible.sync="dialogFormVisible">
 <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign">
  <el-form-item label="姓名">
    <el-input v-model="formLabelAlign.patientName"></el-input>
  </el-form-item>
  <el-form-item label="电话号码">
    <el-input v-model="formLabelAlign.patientPhone"></el-input>
  </el-form-item>
  <el-form-item label="紧急号码">
    <el-input v-model="formLabelAlign.emergencyContactPhone"></el-input>
  </el-form-item>
  <el-form-item label="身份证号">
    <el-input v-model="formLabelAlign.cardId"></el-input>
  </el-form-item>
    <el-form-item label="年龄">
    <el-input  v-model="formLabelAlign.age"  :min="1" :max="100" label="描述文字"></el-input>
  </el-form-item>
  <el-form-item label="就诊部门" >
    <el-select  v-model="formLabelAlign.patientDepartmentId" 
    @change="handleChange()" placeholder="请选择就诊部门" style="width:650px">
       <el-option v-for="(i,p) in bmlist" :key="p" :label="i.departmentName"   :value="i.departmentId"></el-option>
    </el-select>
  </el-form-item>
   <el-form-item label="就诊科目" >
    <el-select v-model="formLabelAlign.patientSubjectId" 
     placeholder="请选择就诊科目"  :disabled="disabled" style="width:650px">
      <el-option v-for="(i,p) in kmlist" :key="p" :label="i.subjectName"  :value="i.subjectId"></el-option>
    </el-select>
  </el-form-item>
     <el-form-item label="医生姓名" >
    <el-select v-model="formLabelAlign.doctorId" 
     placeholder="请选择医生"  :disabled="disabled" style="width:650px">
      <el-option v-for="(i,p) in doctorList" :key="p" :label="i.doctorName"  :value="i.doctorId"></el-option>
    </el-select>
  </el-form-item>
</el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogFormVisible = false">取 消</el-button>
    <el-button type="primary" @click="add">确 定</el-button>
  </div>
</el-dialog>
  </el-card>
</template>
<style>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>

<script>
  export default {
    data() {
      return {
        formInline:{
               patientName:'',
               patientPhone:'',
               region:''
        },
        tableData: [],
        parent:{

        },
        dialogFormVisible: false,
        labelPosition: 'right',
        formLabelAlign: {
                  patientName: "",
                  patientPhone: "",
                  emergencyContactPhone: "",
                  cardId: "",
                  age: "",     
                  patientDepartmentId:"",   
                  patientSubjectId:"",
                  doctorId:"",
          },
         bmlist:[],
         kmlist:[],
         disabled:true,
         doctorList:[],
        }
    },
     mounted() {
         this.regis()
         this.bmjz()
    },
    methods:{
      ToName(){
        if(this.formInline.patientName==""){
             this.$message.error('患者姓名不能为空');
             return;
        }
         if(this.formInline.patientPhone==""){
             this.$message.error('电话号码都不能为空');
             return;
        }
         this.regis();  
         this.$axios.post("/api/biz/drugCharge/toName",this.formInline).then((res)=>{ 
             if(res.data.code==0){
               if(!res.data.data){
                  this.$message.error('该患者不存在');
                  return
               }
                 this.parent=res.data.data;
                 this.parent.trugType=1;
                 this.yaoping();
                  this.$message({
                    message: '查询成功',
                    type: 'success'
                  });
             }
            
         }).catch(function (errorr){
            this.$message.error('有问题请联系开发人员'+errorr);
         })
      },
       regis(){
                this.$axios.post("/api/biz/regis/hfa",this.formLabelAlign).then((res)=>{ 
                            if(res.data.code==0){
                                    this.tableData=res.data.data
                            }else{    
                   }    
            })
       },
        handleChange() {
          this.kmlist=[];
          this.doctorList=[];
          this.formLabelAlign.patientSubjectId=''
          this.formLabelAlign.doctorId=''
          this.disabled=false
          for(var i=0;i<this.bmlist.length;i++){
              if(this.bmlist[i].departmentId==this.formLabelAlign.patientDepartmentId){
                this.kmlist=this.bmlist[i].subjectDTOS;
                break;
              }
          }
           this.$axios.post("/api/biz/regis/byName",this.formLabelAlign).then((res)=>{ 
             if(res.data.code==0){
               this.doctorList=res.data.data
             }  
           })

      },
      add(){
         let z_reg =/^1\d{10}$/;//电话号码格式
         let z_sfz=/^[1-9]\d{5}(18|19|2([0-9]))\d{2}(0[0-9]|10|11|12)([0-2][1-9]|30|31)\d{3}[0-9Xx]$/;//身份证格式
         let reg=/^(?:[1-9][0-9]?|1[01][0-9]|120)$/;//年龄正则
        if(this.formLabelAlign.patientName==""){
             this.$message.error('姓名不能为空');
             return;
        }
         if(!z_reg.test(this.formLabelAlign.patientPhone)){
          this.$message.error('电话号码格式不正确或为空');
             return;
        }
          if(!z_reg.test(this.formLabelAlign.emergencyContactPhone)){
          this.$message.error('紧急号码格式不正确或为空');
             return;
        }
        if(!z_sfz.test(this.formLabelAlign.cardId)){
             this.$message.error('身份证号格式不正确或为空');
             return;
        }
          if(!reg.test(this.formLabelAlign.age)){
           this.$message.error('年龄必须为数字,年龄范围为1-120之间');
             return;
        }
        if(this.formLabelAlign.patientDepartmentId==""){
            this.$message.error('就诊部门不能为空');
            return;
        }
          if(this.formLabelAlign.patientSubjectId==""){
            this.$message.error('就诊科目不能为空');
            return;
        }
        this.$axios.post("/api/biz/regis/add",this.formLabelAlign).then((res)=>{ 
            if(res.data.code==0){
               this.$message({
                    message: '添加成功',
                    type: 'success'
                  });
                this.dialogFormVisible = false;
            }
       })
       
      },
      bmjz(){
                this.$axios.get("/api/biz/department/subject").then((res)=>{ 
                      if(res.data.code==0){
                            var k=0;
                            for(var i=0;i<res.data.data.length;i++){
                                   if(res.data.data[i].subjectDTOS[0].subjectId!=null){
                                               this.bmlist[k]=res.data.data[k];
                                               k++;
                                   } 
                            }
                              console.log(this.bmlist)
                      }else{    
               }    
      })
      }
    }
  }
</script>